package com.ruoyi.project.syl_Sxl.controller;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.syl_Sxl.domain.HisUser;
import com.ruoyi.project.syl_Sxl.service.IHisUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/syl_Sxl/user")
public class HisUserController extends BaseController {
    @Autowired
    private IHisUserService iHisUserService;
    /**
     * 查询所有用户
     *
     * @param
     * @return
     */
    @PreAuthorize("@ss.hasPermi('syl_Sxl:user:query')")
    @GetMapping("/list")
    public TableDataInfo list(HisUser hisUser) {
        startPage();
        List<HisUser> list = iHisUserService.selectAll(hisUser);
        return getDataTable(list);
    }


    /**
     * 新增用户
     * @param hisUser
     * @return
     */
    @PreAuthorize("@ss.hasPermi('syl_Sxl:user:add')")
    @PostMapping
    public AjaxResult add(@Validated @RequestBody HisUser hisUser) {
        hisUser.setCreateBy(SecurityUtils.getUsername());
        return toAjax(iHisUserService.insert(hisUser));
    }

    /*
    * 删除用户
    * */
    @PreAuthorize("@ss.hasPermi('syl_Sxl:user:remove')")
    @DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds){
        return toAjax(iHisUserService.deleteByIds(userIds));
    }

}
